package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author Pan Rundong
 * @Date 2023-02-27 9:43
 * @Desc 黑名单表Api实现类
 */
@DubboService
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 根据用户Id查询
     * @Author: Pan Rundong
     * @param userId
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.tanhua.model.domain.BlackList>
     */
    @Override
    public Page<UserInfo> getById(Long userId, int page, int size) {
        //1.创建Page对象
        Page<UserInfo> pageInfo = new Page<>(page, size);

        //2.调用mapper方法查询
        pageInfo = userInfoMapper.getPage(pageInfo, userId);

        return pageInfo;
    }

    /**
     * 移除黑名单
     *
     * @param uid
     * @param userId
     * @return void
     * @Author Pan Rundong
     */
    @Override
    public void deleteBlackList(Long uid, Long userId) {
        //1.设置条件
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId, userId);
        queryWrapper.eq(BlackList::getBlackUserId, uid);

        //2.删除
        blackListMapper.delete(queryWrapper);
    }


}
